const { resolve } = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    mode:'development',
    entry:'./src/index.js',
    output:{
        filename:'build.js',
        path:resolve(__dirname,'./dist')
    },
    module:{
        rules:[
            {
                test:/\.css$/,
                use:['style-loader','css-loader']
            },
            // svg图标用base64方式处理
            {
                test:/\.svg$/,
                include:[
                    resolve(__dirname,'./src/images')
                ],
                type:'asset/resource',
                //详细配置
                generator:{
                    filename:'icon/[hash:10][ext]',
                }
            },
            // 处理字体文件
            {
                test:/\.(eot|ttf|svg|woff)/,
                include:[
                    resolve(__dirname,'./src/font')
                ],
                type:'asset/resource',
                // 配置
                generator:{
                    filename:'font/[name][ext]',
                }
            },
            // 处理txt文件
            {
                test:/\.txt/,
                include:[
                    resolve(__dirname,'./src/assets')
                ],
                type: 'asset/source',
                // 配置
                generator:{
                    filename:'assets/[name][ext]',
                }

            },
            // 图片文件配置
            {
                test:/\.(jpe?g|png|gif)/i,
                include:[
                    resolve(__dirname,'./src/images')
                ],
                type:'asset',
                //解析
                parser: {
                    //转base64的条件
                    dataUrlCondition: {
                        maxSize: 8 * 1024, // 25kb
                    }
                },
                // 配置
                generator:{
                    filename:'images/[name][ext]',
                }
            },

        ]
    },
    plugins:[
        new htmlWebpackPlugin({
            template:'./src/index.html'
        })
    ]
}